<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 第一步:依赖包 js、css -->
    <script src='./js/swiper.js'></script>
    <link rel="stylesheet" href="./css/swiper.css">
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .swiper-container {
            width: 600px;
            height: 400px;
            margin: 20px auto;
            border: 1px solid black;
        }
    </style>
</head>

<body>
 
    <!-- 第二步:提供轮播图的结构 --完整的结构
          注意:swiper@5
    -->
    <div class="swiper-container">
        <!-- swiper-wrapper 里面放轮播图图片 -->
        <div class="swiper-wrapper">
            <div class="swiper-slide">Slide 1</div>
            <div class="swiper-slide">Slide 2</div>
            <div class="swiper-slide">Slide 3</div>
        </div>
        <!-- 如果需要分页器 -->
        <div class="swiper-pagination"></div>
        <!-- 如果需要导航按钮 -->
        <div class="swiper-button-prev"></div>
        <div class="swiper-button-next"></div>
    </div>
</body>

</html>
<script>
    //第三步:初始化Swiper类的实例
    //两个参数:第一个参数轮播图根节点DOM节点
    let swp = new Swiper(document.querySelector('.swiper-container'), {
        //左侧按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        pagination: {
            el: '.swiper-pagination',
            //分页器类型
            // type:'fraction'
            //点小球也会动
            clickable: true,
        },
    });
    //一定要切记:在初始化Swiper之前,页面中结构必须现有！！！
</script>